#ifndef __RED_STRING_OBJECT_H__
#define __RED_STRING_OBJECT_H__

#include <stdarg.h>
#include "rstring.h"
#include "redobject.h"

typedef struct _RedStringObject
{
	RedObject_HEAD

	int		st_length;
	char	st_buffer[0];
} RedStringObject;

RED_EXPORT extern RedTypeObject RedType_String;

#define RedString_Exact(o)		((o)->ob_type == &RedType_String)
#define RedString_Buffer(o)		(((RedStringObject *)(o))->st_buffer)
#define RedString_Length(o)		(((RedStringObject *)(o))->st_length)
#define RedString_Capacity(o)	(((RedStringObject *)(o))->st_capacity)

RED_EXPORT void Red_FreeStringPool(void);
RED_EXPORT char Red_InitStringPool(void);

RED_EXPORT RedObject *RedString_FromChar(char ch);
RED_EXPORT RedObject *RedString_FromLength(int length);
RED_EXPORT RedObject *RedString_FromRString(rstring_t *s);
RED_EXPORT RedObject *RedString_FromCString(const char *s);		/* <------- this function may intern string `s` if it's length is not too large */
RED_EXPORT RedObject *RedString_FromCFormat(const char *format, ...);
RED_EXPORT RedObject *RedString_FromCFormatVa(const char *format, va_list args);
RED_EXPORT RedObject *RedString_FromBufferAndSize(const char *buffer, int length);

RED_EXPORT RedObject *RedString_Lower(RedObject *self);
RED_EXPORT RedObject *RedString_Upper(RedObject *self);
RED_EXPORT RedObject *RedString_Strip(RedObject *self);
RED_EXPORT RedObject *RedString_Append(RedObject *self, RedObject *other);
RED_EXPORT RedObject *RedString_Format(RedObject *self, RedObject *items);
RED_EXPORT RedObject *RedString_EndsWith(RedObject *self, RedObject *tail);
RED_EXPORT RedObject *RedString_StartsWith(RedObject *self, RedObject *head);

RED_EXPORT RedObject *RedString_AppendCString(RedObject *self, const char *s);
RED_EXPORT RedObject *RedString_AppendCFormat(RedObject *self, const char *format, ...);

RED_EXPORT void RedString_Eat(RedObject *self, size_t length);
RED_EXPORT char RedString_Equals(RedObject *self, RedObject *other);
RED_EXPORT char RedString_EqualsCString(RedObject *self, const char *s);

#endif /* __RED_STRING_OBJECT_H__ */
